package structures;

/**
 * Represents a CTF player, tied to a client.
 * @author lilywong
 *
 */
public class Player {
	
	// player possible attributes, bit vector
	static final int ON_TEAM_1 	= 0x01;
	static final int ON_TEAM_2 	= 0x02;
	static final int HAS_FLAG_1 = 0x04;
	static final int HAS_FLAG_2 = 0x08;
	static final int AT_HOME 	= 0x10;
	static final int IN_JAIL 	= 0x20;
	static final int HAS_BOMBS 	= 0x40;
	
	// instance vars
	int id;
	int state;
	Position pos;
	
	public int getId() { return id; }
	public int getState() { return state; }
	public Position getPos() { return pos; }
	
	public void setPos(Position p) { pos = p; }
	
	// dummy constructor
	public Player(int idP, Position p) {
		id = idP;
		// no state?
		pos = p;
	}
	
	public Player(int id, int team) {
		this.id = id;
		if ( team == 1 )
			state = ON_TEAM_1;
		else
			state = ON_TEAM_2;
	}
	
	// accessors
	public boolean isInJail() {
		return (state & IN_JAIL) != 0;
	}
	public boolean isAtHome() {
		return (state & AT_HOME) != 0;
	}
	public boolean hasBombs() {
		return (state & HAS_BOMBS) != 0;
	}
	public boolean hasFlag1() {
		return (state & HAS_FLAG_1) != 0;
	}
	public boolean hasFlag2() {
		return (state & HAS_FLAG_2) != 0;
	}
	public boolean hasAFlag() {
		return hasFlag1() || hasFlag2();
	}
	
	
	// Team 2 = 10, Team 1 = 01
	// right shift once, add 1 to get team numbers
	public int getTeam() {
		return ((id+1) % 2  )+ 1;
	}
	
	
	
	/* mutators */
	void toggleHasBombs() {
		state = state ^ HAS_BOMBS;
	}
	void toggleAtHome() {
		state = state ^ AT_HOME;
	}
	void toggleHasFlag1() {
		state = state ^ HAS_FLAG_1;
	}
	void toggleHasFlag2() {
		state = state ^ HAS_FLAG_2;
	}
	void toggleInJail() {
		state = state ^ IN_JAIL;
	}
	

}
